<?php require("inc/common.inc.php");
$web_title = "预约服务";
if ($actions=="save"){
	if(empty($_COOKIE['userid']) || $_COOKIE['userid']=="" || empty($_COOKIE['username']) || $_COOKIE['username']==""){
		$return["success"]=false;
		$return["msg"]="您需要登录后才可以预约服务。";
		echo json_encode($return);
		exit();
	}else{
		$mxuserid = $_COOKIE['userid'];
		$mxusername = $_COOKIE['username'];
		$mxnickname = $_COOKIE['nickname'];
	}
  $return="";
  if($mobile==""){
  	$return["success"]=false;
  	$return["msg"]="联系电话不能为空";
	echo json_encode($return);
  	exit();
  }
  if($name==""){
  	$return["success"]=false;
    $return["msg"]="姓名不能为空";
	echo json_encode($return);
    exit();
  }
  if($time==""){
  	$return["success"]=false;
  	$return["msg"]="预约时间不能为空";
	echo json_encode($return);
  	exit();
  }
  if($content==""){
  	$return["success"]=false;
  	$return["msg"]="预约内容不能为空";
  	echo json_encode($return);
  	exit();
  }
  $content=dvHTMLEncode($content);
  
  $files=array(
  		"userid" =>$mxuserid,
        "mobile"      =>$mobile,
        "name"    =>$name,
        "time"    =>$time,
        "content"  =>$content,
        "createtime"  =>date('Y-m-d H:i:s'),
  );
  $db->exe_insert("mx_app_reserve",$files);
  $return["success"]=true;
  $return["msg"]="预约信息提交成功，稍后会有客服联系您！";
  echo json_encode($return);
  exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1" name="viewport">
<head>
<title><?php echo $web_title?></title>
<meta name="searchtitle" content="<?php echo $web_title2.$webdb['metakeywords'];?>">
<meta name="description" content="<?php echo $web_title2.$webdb['webdsc'];?>">
<meta name="keywords" content="<?php echo $web_title2.$webdb['metakeywords'];?>">
<?php 
require("w_head.php");?>
<link type="text/css" rel="stylesheet" href="/css/mr.css">
<style type="text/css">
<!--
.sednav li {border: 1px solid #ff84bd;
background:-webkit-linear-gradient(top,#fff2f9,#fedcec);background:linear-gradient(top,#fff2f9,#fedcec);
padding: 0.5em;
font-size: 1.725em;
margin: 0.5em 0.5em 0 0;
text-align: center;
-moz-border-radius: .3em;
-webkit-border-radius: .3em;
border-radius: .3em;
width: 25%;
float: left;
}
.sednav a, .sednav a:hover{ color:#dc4089;}
-->
</style>


<script type="text/javascript"> 
		$(document).ready(function () { 
			$("#reserveBtn").click(function () {
				var btn = $(this);
				var mobile = $("#mobile").val();
				if (mobile  == '' || mobile == '请填写预约手机号码') {
					alert("请输入预约手机号码");
					$("#mobile").focus();
					return;
				}
				else{
					var pattern=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{7,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}1[0-9]{10}$)/; 
					if(!pattern.test(mobile)) 
					{ 
						alert("手机号码格式错误");
						$("#mobile").focus();
						return;
					} 
				}
				var name = $("#name").val();
				if (name  == '' || name == '请填写预约姓名') {
					alert("请输入预约姓名");
					$("#name").focus();
					return;
				}
				var time = $("#time").val();
				if (time == '' || time == '请选择预约时间') {
					alert("请选择预约时间");
					$("#time").focus().click();
					return;
				}
				var content = $('#content').val();
				if (content == '' || content == '请填写预约内容') {
					content = '';
				}
				var submitData = {
					mobile:mobile,
					name:name,
					time:time,
					content: content,
					actions: "save",
				};
				$.post('#', submitData,
					function(data) {
						if (data.success == true) {
							alert(data.msg);
							setTimeout('window.location.href=location.href',1000);
						return;
					} else {
						alert(data.msg);
					}
				},
				"json")
			}); 
		}); 
	</script>
</head>

<body style="background-color:#fff5fb; padding-bottom:55px;">

<form name="reserveForm" method="post" action="reserve.php?actions=save" id="reserveForm" onsubmit="">
<!--主体-->
<div class="viewport">
    <div class="witbox">
    <div class="bespeak">
        <ul>
            <li>
            	<input type="text" onblur="if(this.value==''){this.value='请填写预约手机号码';}" onfocus="if(this.value=='请填写预约手机号码'){this.value=''}" value="请填写预约手机号码" id="mobile" class="yy_inp" name="mobile">
            </li>
            <li>
                <input type="text" onblur="if(this.value==''){this.value='请填写预约姓名';}" onfocus="if(this.value=='请填写预约姓名'){this.value=''}" value="请填写预约姓名" id="name" class="yy_inp" name="name">
            </li>
            <li>
                <select name="project" id="project" class="yy_inp" style="width:100%">
                <option value="">请选择预约项目</option>
                <option value="剪发">剪发</option>
                <option value="烫发">烫发</option>
                <option value="护理">护理</option>
                <option value="美甲">美甲</option>
                </select>
            </li>
            <li>
                <input type="text" readonly onblur="if(this.value==''){this.value='请选择预约时间';}" onfocus="if(this.value=='请选择预约时间'){this.value=''}" value="请选择预约时间" id="time" class="yy_inp" name="time">
                <script type="text/javascript" src="/js/calendar.js"></script>
  <script language="javascript" type="text/javascript">
  Calendar.setup({
	  inputField     :    "time",
	  ifFormat       :    "%Y-%m-%d %H:%M",
	  showsTime      :    true,
	  timeFormat     :    "24"
  });
  </script>
            </li>
        </ul>
    <div class="beizhu">
        <textarea name="content" cols="" rows="" class="bz_tex" id="content" onFocus="if(this.value=='请填写预约内容'){this.value=''}" onBlur="if(this.value==''){this.value='请填写预约内容'}">请填写预约内容</textarea>
        <p>
            <input type="butten" id="reserveBtn" value="提交" class="bz_btn">
        </p>
    </div>
    </div>
</div>
</div>
</form>
<?php require("w_foot.php")?>